package com.tang4j.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.tang4j.core.model.AbstractModel;
import com.tang4j.model.response.ThSysNavigationDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * <p>
 * 角色表
 * </p>
 *
 * @author saber
 * @since 2019-11-18
 */
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@Data
@ApiModel(value = "ThSysRole", description = "角色表")
public class ThSysRole extends AbstractModel {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "系统编码")
    @TableField("os_code")
    private String osCode;


    @ApiModelProperty(value = "名称")
    @TableField("name")
    private String name;


    @ApiModelProperty(value = "描述")
    @TableField("description")
    private String description;


    @ApiModelProperty(value = "状态")
    @TableField("state")
    private Integer state;


    @ApiModelProperty(value = "排序")
    @TableField("order_no")
    private Integer orderNo;

    @ApiModelProperty(value = "编码")
    @TableField("code")
    private String code;

    @ApiModelProperty(value = "菜单id")
    @TableField(exist = false)
    private String navigationId;

    /**
     * 菜单列
     */
    @TableField(exist = false)
    private List<ThSysNavigationDto> thSysNavigationDtoList;


    public ThSysRole(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public String getOsCode() {
        return osCode;
    }

    public void setOsCode(String osCode) {
        this.osCode = osCode;
    }

    public String getName() {
        return name;
    }

    /**
     * Spring Security 4.0以上版本角色都默认以'ROLE_'开头
     *
     * @param name role名
     */
    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(Integer orderNo) {
        this.orderNo = orderNo;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        if (!code.contains("ROLE_")) {
            this.code = "ROLE_" + code;
        } else {
            this.code = code;
        }
    }

    public String getNavigationId() {
        return navigationId;
    }

    public void setNavigationId(String navigationId) {
        this.navigationId = navigationId;
    }
}
